package com.aote.expression.paramprocessor;

import java.util.Iterator;
import java.util.Map;

import org.w3c.dom.Element;

import com.aote.expression.Param;
import com.browsesoft.baseadapter.HTMLLazyTableModel;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.browsesoft.user.User;

public class AmountProcessor implements ParamProcessor {

	public String process(Param param, Map attribures, User loginUser,
			HTMLBasicComponent component) throws NoFitValueException {
		Map map = param.getParams();
		String entitytype = (String) map.get("entitytype");
		String attribute = (String) map.get("attribute");
		// 找相匹配的表格组件
		Iterator iter = component.getChildrenComponents();
		while (iter.hasNext()) {
			HTMLBasicComponent child = (HTMLBasicComponent) iter.next();
			Element element = child.getElement();
			String str = element.getAttribute("entitytype");
			String mod = element.getAttribute("model");
			// 当组件实体类型相匹配，且模型为HTMLLazyTableModel，进行计算
			if (mod.endsWith("HTMLLazyTableModel") && str.equals(entitytype)) {
				HTMLLazyTableModel model = (HTMLLazyTableModel) child
						.getModel();
				String result = model.getSumByColName(attribute);
				return result;
			}
		}
		return null;
	}

}
